package org.utils.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;

/**
 * @author Manuel EVENO
 */
public abstract class EnhancedHttpServlet extends HttpServlet
{
	protected Logger logger = null;
	private String path = null;
	/**
	 * @see javax.servlet.http.HttpServlet#init()
	 */
	public void init() throws ServletException
	{
		super.init();
		try
		{
			path = getServletContext().getRealPath(".");
			path = path.substring(0, path.length()-1);

			BasicConfigurator.configure(new FileAppender(new PatternLayout("[%d] %-5p %c{1}.%M(%L) - %m%n"), path+"debug.log", false));
			logger = Logger.getLogger( getClass() );

			logger.debug("current.path: "+path);
		}
		catch (IOException e)
		{
			throw new ServletException(e);
		}
	}
//
//	protected void validate(String name, String value) throws ServletException
//	{
//	        logger.debug("Validating "+name+": "+value);
//	        if (value == null || value.length() == 0)
//	        	throw new ServletException("Missing parameter "+name);
//	}
	
	public String getPath()
	{
		return path;
	}
}